import {takeEvery} from 'redux-saga'
import VideoMiddleware from './VideoMiddleware'
import UserMiddleware from './UserMiddleware'
import PetMiddleware from './PetMiddleware'
import { put } from 'redux-saga/effects'
import { ActionTypes } from '../constants'
import FileMiddleware from './FileMiddleware';

const apiMap = {
	[ActionTypes.API_GET_VIDEO_LIST]: VideoMiddleware.getVideoList,
	[ActionTypes.API_GET_PET_VIDEO_BY_PET_ID]: VideoMiddleware.fetchPetVideoList,
	[ActionTypes.API_GET_USER_VIDEO_LIST_BY_USER]: VideoMiddleware.fetchUserVideoList,

	[ActionTypes.API_REGISTER]: UserMiddleware.fetchRegister,
	[ActionTypes.API_LOGIN]: UserMiddleware.fetchLogin,
	[ActionTypes.API_GET_PETS_BY_USER_ID]: PetMiddleware.fetchPetListByUser,

	// file
	[ActionTypes.API_CHANGE_HEAD_IMAGE]: FileMiddleware.fetchUploadHeadImage,
	[ActionTypes.API_CHANGE_PET_IMAGE]: FileMiddleware.fetchUploadPetImage,

	// user
	[ActionTypes.API_CHANGE_USER_INFO]: UserMiddleware.fetchUpdateUserInfo,
	[ActionTypes.API_RELATE_USER_BY_TYPE]: UserMiddleware.fetchUpdateRelate,
}

const apiService = function*(action) {
	const {type, payload} = action;
	switch (type) {

	}

	// 使用映射绑定
	if (apiMap.hasOwnProperty(type)) {
		yield apiMap[type](payload)
	}
}

const mySaga = function* mySaga() {
	yield* takeEvery(
		action => {
			return action
		}, apiService
	)
}

export default mySaga
